home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998…tember: Reference Library / Dev.CD Sep 98 RL2.toast / What's New / Software Development Kits / MacOS USB DDK / Examples / PrinterClassDriver / PrinterClassDriver.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-20  |  6.5 KB  |  220 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PrinterClassDriver.h
  3.  
  4.     Contains:    structures for PrinterClass
  5.  
  6.     Version:    
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11. #ifndef __PRINTERCLASSDRIVERH__
  12. #define __PRINTERCLASSDRIVERH__
  13.  
  14. #include <MacTypes.h>
  15. #include <Devices.h>
  16. #include <DriverServices.h>
  17. #include <Processes.h>
  18.  
  19. #ifndef __MIXEDMODE__
  20. #include <mixedmode.h>
  21. #endif
  22.  
  23. #include <USB.h>
  24.  
  25. #if DEBUG
  26. #define IF_DEBUG(x)    x
  27. #else
  28. #define IF_DEBUG(x)
  29. #endif
  30.  
  31. #define kStrPrinterClass    "PrinterClass: "
  32. void DriverEntry(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  33. void ExpertNotify(void *exNote);
  34.  
  35. #define kPrinterRetryCount    5
  36.  
  37. /* Move to sys files */
  38. #define kUSBPrintClass 7
  39. #define kUSBPrintSubClass 1
  40.  
  41.  
  42. // section 5.3 USB Device Class Definition for Printing Devices
  43. enum {
  44.     kUSBPrintClassGetDeviceID = 0,
  45.     kUSBPrintClassGetCentronicsStatus = 1,
  46.     kUSBPrintClassSoftReset = 2,
  47.     kUSBPrintClassProtocolReserved = 0,
  48.     kUSBPrintClassProtocolUnidirectional = 1,
  49.     kUSBPrintClassProtocolBidirectional = 2,
  50.     // 3..0xFE reserved for future use
  51.     kUSBPrintClassProtocolVendor = 0xFF
  52. };
  53.  
  54. enum 
  55. {
  56.     kDrvrCentronicsStatus = 3,
  57.     kDrvr1284IdString = 4,
  58.     kDrvrNumDevices = 5,
  59.     kDrvrSoftReset = 6,
  60.     kDrvrPrivateSetStorage = 128
  61. };
  62.  
  63. enum driverstages
  64. {
  65.     kUndefined = 0,
  66.     kNilCompletion,
  67.     kFindInterface,
  68.     kSetInterface,
  69.     kGetConfigurationDescriptor,
  70.     kGetFullConfiguration,
  71.     kGetCapabilityString,
  72.     kDelayGetCapability,
  73.     kGetFullCapabilityString,
  74.     kGetInterface,
  75.     kOpenBulkOutPipe,
  76.     kOpenBulkInPipe,
  77.     kEnterNameRegistry,
  78.     kReturnFromDriver = 0x1000,
  79.     kRetryTransaction = 0x2000,
  80.     kAsyncTransaction = 0x4000,
  81.     kTransactionPending = 0x8000
  82. };
  83.  
  84. enum {
  85.     uppIODoneProcInfo = kRegisterBased
  86.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  87.          | REGISTER_RESULT_LOCATION(kRegisterD0)
  88.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(OSErr)))
  89.          | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(IOParamPtr)))
  90.          | REGISTER_ROUTINE_PARAMETER(3, kRegisterA1, SIZE_CODE(sizeof(DCtlHandle))),
  91.  
  92.     uppQueueUSBReadProcInfo = kCStackBased
  93.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  94.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  95.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  96.  
  97.     uppQueueUSBWriteProcInfo = kCStackBased
  98.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  99.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  100.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  101.  
  102.     uppAbortProcInfo = kCStackBased
  103.          | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
  104.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DriverRefNum)))
  105.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  106.  
  107.     uppControlStatusProcInfo = kCStackBased
  108.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  109.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  110.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *)))
  111. };
  112.  
  113. #if GENERATINGCFM
  114. typedef UniversalProcPtr    QueueUSBReadUPP;
  115. typedef UniversalProcPtr    QueueUSBWriteUPP;
  116. typedef UniversalProcPtr    IODoneUPP;
  117. typedef UniversalProcPtr    AbortUPP;
  118. typedef UniversalProcPtr    ControlStatusUPP;
  119. #else
  120. typedef ProcPtr                QueueUSBReadUPP;
  121. typedef ProcPtr                QueueUSBWriteUPP;
  122. typedef ProcPtr                IODoneUPP;
  123. typedef ProcPtr                AbortUPP;
  124. typedef ProcPtr                ControlStatusUPP;
  125. #endif
  126.  
  127. typedef struct {
  128.     OSErr        err;
  129.     IOParamPtr    pb;
  130.     DCtlPtr        ctl;
  131. } DrvrParams;
  132.  
  133. typedef struct usbPrinterPBStruct
  134. {
  135.     //
  136.     //    note: first element must be USBPB pb
  137.     //        since we often cast it to usbPrinterPBStruct
  138.     //
  139.     USBPB                             pb,                    // configuration block
  140.                                     out,                // map client write
  141.                                     in;                    // map client read
  142.     //
  143.     //    optional bulk in pipe
  144.     //
  145.     USBEndPointDescriptorPtr        readDescriptor;        // configuration/interface info
  146.     USBPipeRef                         readPipe;            // USB pipe reference
  147.     QueueUSBReadUPP                    qread,                // queue USB read from 68K
  148.                                     r;
  149.     RoutineDescriptor                qreadRD;            // static descriptor
  150.     DrvrParams                        readDrvr;            // currently active read
  151.     //
  152.     //    mandatory bulk out pipe
  153.     //
  154.     USBEndPointDescriptorPtr        writeDescriptor;    // configuration/interface info
  155.     USBPipeRef                         writePipe;            // USB pipe reference
  156.     QueueUSBWriteUPP                qwrite,                // queue USB write from 68K
  157.                                     w;
  158.     RoutineDescriptor                qwriteRD;            // static descriptor
  159.     DrvrParams                        writeDrvr;            // currently active read
  160.     //
  161.     //    abort/cancel transactions
  162.     //
  163.     AbortUPP                        qabort,                // cancel from 68K DRVR
  164.                                     a;
  165.     RoutineDescriptor                qabortRD;            // static descriptor
  166.     //
  167.     //    status transactions
  168.     //
  169.     ControlStatusUPP                qstatus,            // simple status from 68K DRVR
  170.                                     s;
  171.     RoutineDescriptor                qstatusRD;            // static descriptor
  172.     DrvrParams                        statusDrvr;            // currently active status request
  173.     //
  174.     //    unit table driver names and refNums
  175.     //
  176.     DRVRHeaderHandle                hDrvr;                // detached from class driver resource file
  177.     DriverRefNum                    outRefNum;            // write unit table ref
  178.     DriverRefNum                    inRefNum;            // read unit table ref
  179.     Str255                            driverOutName;        // write driver name in unit table
  180.     Str255                            driverInName;        // read driver name in unit table
  181.     //
  182.     //    device: configuration and interface details
  183.     //
  184.     UInt8                            terminating;        // offline USS-720 device
  185.     USBDeviceRef                    device;                // USB device reference
  186.  
  187.     USBDeviceDescriptor             desc;                // copy for local reference
  188.     USBInterfaceDescriptorPtr        interface;            // copy for local reference
  189.     UInt32                            interfaceOffset;    // result/param for USB calls
  190.     UInt8                            whichAltInterface;
  191.  
  192.     Str255                            name;                // printer name in name registry
  193.  
  194.     unsigned char                    *capabilityString;    // 1284 capability string
  195.     USBConfigurationDescriptorPtr    config;                // USB configuration string
  196.  
  197.     unsigned char                    capability[256];    // capability: try not to fragment storage
  198.     unsigned char                    configuration[256];    // configuration: try not to fragment storage
  199.     //
  200.     //    class driver async transactions
  201.     //
  202.     SInt32                            transDepth;            // don't nest transactions
  203.     SInt32                             retryCount;            // automatically retry transactions
  204.  
  205. };
  206.  
  207.  
  208. OSStatus OpenBulkEndpoint(struct usbPrinterPBStruct    *pPrinterPB, UInt32    refCon);
  209. OSStatus Abort( DriverRefNum refNum, struct usbPrinterPBStruct *pPrinterPB );
  210. void     ControlStatusRequests( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  211. void     QueueRead( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  212. void     QueueWrite( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  213.  
  214. void      PrintDriverEntry(USBDeviceRef device,USBDeviceDescriptorPtr desc, USBInterfaceDescriptorPtr pInterface);
  215. OSStatus PrintDriverFinalize( void );
  216.  
  217.  
  218.  
  219.  
  220. #endif //__PRINTERCLASSDRIVERH__